package com.sky.mapper;


import com.sky.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;


@Mapper
public interface UserMapper {

    @Select("select * from user where openid = #{openid}")
    User getByOpenid(String openid);

    void insert(User user);

    //根据用户id查找用户
    @Select("select * from user where id = #{userId}")
    User getById(Long userId);
    //查询指定日期内的每天新注册用户
    @Select("select DATE_FORMAT(create_time,'%Y-%m-%d') date1,count(*) userAll from user where create_time " +
            "between #{begin} and #{end} group by DATE_FORMAT(create_time,'%Y-%m-%d')")
    List<Map> getUserStatistics(LocalDate begin, LocalDate end);
    //查询查询开始日期前一天的用户总量
    @Select("select count(*) from user where DATE_FORMAT(create_time,'%Y-%m-%d') <= #{time}")
    int getUserCountBytTime(LocalDate time);
    //查询指定日期内的新增用户
    @Select("select count(*) from user where DATE_FORMAT(create_time,'%Y-%m-%d') between #{begin} and #{end}")
    int getUserCountOnTime(LocalDate begin,LocalDate end);

}
